home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#11 (Aug 86)
/
forth
/
mul.sp (revised)
< prev
Wrap
Text File
|
1986-06-03
|
2KB
|
89 lines
( 32 bit floating point routines, 27.4.1986 J. Langowski )
CODE S* ( 32 bit single precision multiply)
MOVE.L (A6)+,D1
BEQ @zero
MOVE.L (A6)+,D0
BEQ @end
( D0,D1 will be used for lower 16 bits of mantissa.
D2,D3 for exponent )
MOVE.L D0,D2
MOVE.L D1,D3
SWAP.W D2
SWAP.W D3
( get rid of junk in D4,D5 )
CLR.W D4
CLR.W D5
( move most significant 7 mantissa bits to D4,D5
and set implied highest bit = 1 )
MOVE.B D2,D4
MOVE.B D3,D5
BSET #7,D4
BSET #7,D5
( isolate exponent + sign in D2,D3 )
( ANDI.W #$FF80,D2 )
DC.L $0242FF80
( ANDI.W #$FF80,D3 )
DC.L $0243FF80
( rotate sign into lowest bit D2,D3 )
ROL.W #1,D2
ROL.W #1,D3
( subtract exponent offset )
SUBI.W #$7F00,D2
SUBI.W #$7F00,D3
( sum exponents, check for over- or underflow )
ADD.W D2,D3
BVS @ovflchk
( now do 24*24 bit multiplication of mantissa )
MOVE.W D4,D2 ( u-hi -> D2 )
MULU.W D1,D2 ( u-hi * v-lo -> D2 )
MULU.W D0,D1 ( u-lo * v-lo -> D1 )
MULU.W D5,D0 ( u-lo * v-hi -> D0 )
MULU.W D4,D5 ( u-hi * v-hi -> D5 )
ADD.L D2,D0 ( u-hi*v-lo + u-lo*v-hi -> D0 )
MOVE.W D5,D1 ( u-hi*v-hi -> LSW[D1], MSW unchanged )
SWAP.W D1
ADD.L D1,D0 ( put it all together )
( highest mantissa bit might have changed to one )
BPL @nohibit
ADDI.W #$100,D3
BVC @round
BRA @ovflchk
@nohibit ADD.L D0,D0
@round BTST #7,D0
BEQ @blk.exp
BTST #6,D0
BNE @incr
BTST #8,D0
BEQ @blk.exp
@incr ADDI.L #$80,D0
BCC @blk.exp
ADDI.W #$100,D3
BVC @blk.exp
@ovflchk BPL @makezero
MOVE.L #$7F800000,-(A6)
RTS
@makezero CLR.L D0
MOVE.L D0,-(A6)
RTS
@zero CLR.L D0
MOVE.L D0,(A6)
RTS
( readjust exponent )
@blk.exp ADDI.W #$7F00,D3
BLE @makezero
ROR.W #1,D3
( ANDI.W #$FF80,D3 )
DC.L $0243FF80
LSR.L #8,D0
BCLR #23,D0
SWAP.W D3
CLR.W D3
OR.L D3,D0
@end MOVE.L D0,-(A6)
RTS
END-CODE